package com.example.bookcar.service.impl;

import com.example.bookcar.entity.CarType;
import com.example.bookcar.service.CarTypeService;
import com.example.bookcar.mapper.CarTypeMapper;
import com.example.bookcar.vo.PageData;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author 18225
* @description 针对表【t_car_type】的数据库操作Service实现
* @createDate 2023-03-06 14:54:23
*/
@Service
public class CarTypeServiceImpl implements CarTypeService{

    @Autowired
    CarTypeMapper carTypeMapper;

    @Override
    public PageData listCarTypes(Integer currentPage, Integer pageSize, String name) {
        PageHelper.startPage(currentPage, pageSize);
        Page<CarType> page = carTypeMapper.listCarTypes(name);
        return new PageData(page.getTotal(), page.getResult());
    }

    @Override
    public CarType getCarTypeById(Integer id) {
        return carTypeMapper.getCarTypeById(id);
    }

    @Override
    @Transactional
    public int updateCarType(com.example.bookcar.entity.CarType carType) {
        return carTypeMapper.updateCarType(carType);
    }

    @Override
    public int deleteCarTypeById(Integer id) {
        return carTypeMapper.deleteCarTypeById(id);
    }

    @Override
    @Transactional
    public int insertCarType(CarType carType) {
        return carTypeMapper.insertCarType(carType);
    }
}
